package com.beamfield.controller.manage.lab;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.beamfield.common.ApiResult;
import com.beamfield.common.CommonUtils;
import com.beamfield.common.FileUtil;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.*;
import com.beamfield.modelVo.*;
import com.beamfield.service.manage.lab.DetecTionService;
import com.beamfield.service.manage.sys.FileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 试验检测
 */
@Controller
@RequestMapping("/cms/lab/detection")
public class DetectionController extends BaseController{

    private static final Logger log = LoggerFactory.getLogger(DetectionController.class);
    private final DetecTionService detecTionService;

    @Autowired
    public DetectionController(DetecTionService detecTionService) {
        this.detecTionService = detecTionService;
    }

    @Resource
    private FileService fileService;

    @Value("${uploadFilePath}")
    private String uploadFilePath;

    @Value("${uploadTempPath}")
    private String uploadTempPath;
    @Value("${fileRootUrl}")
    private String fileRootUrl;

    @RequestMapping(value = "/detection",method = RequestMethod.GET)
    public ModelAndView detection(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/material_detec",method = RequestMethod.GET)
    public ModelAndView materialDetec(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_order",method = RequestMethod.GET)
    public ModelAndView lab_order(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/huitanfa",method = RequestMethod.GET)
    public ModelAndView huitanfa(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/addHuitanfa",method = RequestMethod.GET)
    public ModelAndView addHuitanfa(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/editHuitanfa",method = RequestMethod.GET)
    public ModelAndView editHuitanfa(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/addGangjinbaohu",method = RequestMethod.GET)
    public ModelAndView addGangjinbaohu(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/editGangjinbaohu",method = RequestMethod.GET)
    public ModelAndView editGangjinbaohu(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/gangjinbaohu",method = RequestMethod.GET)
    public ModelAndView gangjinbaohu(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/concrete_mix_design",method = RequestMethod.GET)
    public ModelAndView concreteMixDesign(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/concrete_mix_design_entrust",method = RequestMethod.GET)
    public ModelAndView concreteMixDesignEntrust(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/concrete_mixratio",method = RequestMethod.GET)
    public ModelAndView concreteMixratio(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/mixtureabl",method = RequestMethod.GET)
    public ModelAndView mixtureabl(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_mixtureabl",method = RequestMethod.GET)
    public ModelAndView editMixtureabl(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/mechanics",method = RequestMethod.GET)
    public ModelAndView mechanics(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_mc_cm",method = RequestMethod.GET)
    public ModelAndView editMcCm(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_mc_yzl",method = RequestMethod.GET)
    public ModelAndView editMcYzl(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_mc_czl",method = RequestMethod.GET)
    public ModelAndView editMcCzl(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_mc_zzl",method = RequestMethod.GET)
    public ModelAndView editMcZzl(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/pipe_grouting",method = RequestMethod.GET)
    public ModelAndView pipeGrouting(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_pipe_grouting",method = RequestMethod.GET)
    public ModelAndView editPipeGrouting(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/ground_bearer",method = RequestMethod.GET)
    public ModelAndView groundBearer(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/scene/edit_ground_bearer",method = RequestMethod.GET)
    public ModelAndView editGroundBearer(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/geotechnical",method = RequestMethod.GET)
    public ModelAndView geotechnical(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/geotechnical_edit",method = RequestMethod.GET)
    public ModelAndView geotechnical_edit(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/geotechnical_result",method = RequestMethod.GET)
    public ModelAndView geotechnical_result(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_order_list",method = RequestMethod.GET)
    public ModelAndView lab_order_list(){
        return new ModelAndView();
    }
    /**
     * 获取原材料试验委托单
     * @param request
     * @return
     */
    @RequestMapping(value = "/readSuppliesDetectData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readSuppliesDetectData(HttpServletRequest request){
        String suppliesName = request.getParameter("suppliesName");
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        Long beamId = super.getBeamId(request);
        PageResult suppliesDetectData = detecTionService.getSuppliesDetectData(suppliesName, beamId, offset, limit,start,end);
        return suppliesDetectData;
    }

    /**
     * 新增原材料种类名称
     * @param request
     * @return
     * @author anruoxin
     * 2019年4月22日
     */
    @RequestMapping(value = "/addCategory",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult addCategory(HttpServletRequest request, String name){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return detecTionService.addCategory(name, beamId, userId);
    }

    /**
     * 获取原材料列表
     * @param request
     * @return
     * @author anruoxin
     * 2019年4月22日
     */
    @RequestMapping(value = "/getCategory",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getCategory(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        return detecTionService.getCategory(beamId);
    }

    /**
     * 导出原材料检验
     * @param response
     * @param suppliesName
     * @param start
     * @param end
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportSuppliesDetectData")
    @ResponseBody
    public String exportSuppliesDetectData(HttpServletResponse response,String suppliesName,String start, String end, HttpServletRequest request) throws Exception {
        Long beamId = super.getBeamId(request);
        if("undefined".equals(suppliesName)){
            suppliesName=null;
        }
        return detecTionService.exportSuppliesDetectData(response,suppliesName,beamId,start,end);
    }

    /**
     * 委托单驳回操作
     * @param request
     * @return
     */
    @RequestMapping(value = "/reEdit",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult reEdit(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);

        String inboundCheckId = request.getParameter("inbound_check_id");
        String remark = request.getParameter("remark");

        return detecTionService.reEdit(Long.parseLong(inboundCheckId),remark,beamId,userId);
    }
    /**
     * 委托单详情
     * @param request
     * @return
     */
    @RequestMapping(value = "/getCheckInfo",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getCheckInfo(HttpServletRequest request){
        String inboundCheckId = request.getParameter("inbound_check_id");

        return detecTionService.getCheckInfo(Long.parseLong(inboundCheckId));
    }

    /**
     * 获取原材料试验委托单  且有试验结果
     * @param request
     * @return
     */
    @RequestMapping(value = "/readSuppliesDetectDataUnpass",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readSuppliesDetectDataUnpass(HttpServletRequest request){
        String suppliesName = request.getParameter("suppliesName");
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String ispass=request.getParameter("ispass");
        String check_num=request.getParameter("check_num");
        String start=request.getParameter("start");
        String end=request.getParameter("end");
        Long beamId = super.getBeamId(request);
        PageResult suppliesDetectDataUnpass = detecTionService.getSuppliesDetectDataUnpass(suppliesName, beamId, offset, limit,ispass,check_num,start,end);
        return suppliesDetectDataUnpass;
    }

    /**
     * 委外资质管理列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/readSuppliesDetectDataOut",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readSuppliesDetectDataOut(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        PageResult suppliesDetectDataOut = detecTionService.getSuppliesDetectDataOut(beamId, offset, limit);
        return suppliesDetectDataOut;
    }

    /**
     * 获取混凝土理论配合比试验委托单
     * @param request
     * @return
     */
    @RequestMapping(value = "/readConcreteEntrustData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readConcreteEntrustData(HttpServletRequest request){
        String name = request.getParameter("name");
        String id = request.getParameter("id");
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        String status = request.getParameter("status");
        Long beamId = super.getBeamId(request);
        List<ConcreteEntrustVo> concreteEntrustVoList = detecTionService.getConcreteEntrustData(id, name, beamId, offset, limit,start,end,status);
        long total = detecTionService.countConcreteEntrustData(id, name, beamId,start,end,status);
        return new PageResult(total, CommonUtils.parseLong(offset, 0L), concreteEntrustVoList);
    }

    /**
     * 删除理论配合比
     * @param request
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月16日
     */
    @RequestMapping(value = "/delConcreteEntrustData",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delConcreteEntrustData(HttpServletRequest request, Long id){

    	if (id != null) {
    		return detecTionService.delConcreteEntrustData(id);
        }else  {
        	ApiResult apiResult = new ApiResult();
            apiResult.setMessage("未获取到该信息");
            apiResult.setCode("500");
            return  apiResult;
        }
    }

    /**
     * 保存配合比意见
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveMixAdvice",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveMixAdvice(HttpServletRequest request){
        String id = request.getParameter("id");
        String advice = request.getParameter("advice");
        detecTionService.saveMixAdvice(Long.parseLong(id),advice);
        return new ApiResult();
    }

    /**
     * 修改制件日期
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateMakeDate",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateMakeDate(HttpServletRequest request,Long id,String date,Integer type){
        detecTionService.updateMakeDate(id,date,type);
        return new ApiResult();
    }

    @RequestMapping(value = "/updateTestDate",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateTestDate(HttpServletRequest request,Long id,String date){
        detecTionService.updateTestDate(id,date);
        return new ApiResult();
    }

    /**
     * 修改开盘证原材料
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveOpeningSupplies",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveOpeningSupplies(HttpServletRequest request,ConcreteOpeningSupplies openingSupplies){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        detecTionService.saveOpeningSupplies(openingSupplies,userId,beamId);
        return new ApiResult();
    }

    /**
     * 获取开盘证原材料
     * @param request
     * @return
     */
    @RequestMapping(value = "/getOpeningSupplies",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getOpeningSupplies(HttpServletRequest request,Long openingId){
        Long beamId = super.getBeamId(request);
        return new ApiResult(detecTionService.getOpeningSupplies(openingId,beamId));
    }

    /**
     * 保存混凝土理论配合比委托单
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/saveConcreteEntrust",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveConcreteEntrust(HttpServletRequest request,String noticeid){
        String concreteEntrustJson = request.getParameter("concreteEntrustJson");
        String concreteParamJson = request.getParameter("concreteParamJson");
        if(StringUtils.isEmpty(concreteEntrustJson) || StringUtils.isEmpty(concreteParamJson)||StringUtils.isEmpty(noticeid)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            ConcreteEntrust concreteEntrust = JSON.parseObject(concreteEntrustJson, ConcreteEntrust.class);
            ConcreteParam concreteParam = JSON.parseObject(concreteParamJson, ConcreteParam.class);
            result = detecTionService.saveConcreteEntrust(concreteEntrust, concreteParam, beamId, userId,noticeid);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 获取混凝土理论配合比委托单单号
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getCEntrustNum", method = RequestMethod.GET)
    public ApiResult getCEntrustNum(HttpServletRequest request){
        String workdept = request.getParameter("workdept");
        Long beamId = super.getBeamId(request);
        if(StringUtils.isEmpty(workdept)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        String cEntrustNum = detecTionService.getCEntrustNum(beamId, workdept);
        return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage(), cEntrustNum);
    }

    @RequestMapping(value = "/scene/addScene",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult addScene(String noticeId,Integer type,HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            result = detecTionService.addScene(noticeId, type, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 更新混凝土拌和物性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/updateMixtureabl",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateMixtureabl(HttpServletRequest request){
        String mixtureablJson = request.getParameter("mixtureablJson");
        if(StringUtils.isEmpty(mixtureablJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            ConcreteMixtureabl concreteMixtureabl = JSON.parseObject(mixtureablJson, ConcreteMixtureabl.class);
            if(concreteMixtureabl.getId() == null){
                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
            }
            result = detecTionService.updateMixtureabl(concreteMixtureabl, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 获取混凝土拌和物性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/readConcreteMixtureablData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readConcreteMixtureablData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        List<ConcreteMixtureablVo> concreteMixtureablVoList = detecTionService.getConcreteMixtureablData(beamId, offset, limit, noticeId, partDate);
        long total = detecTionService.countConcreteMixtureablData(beamId, noticeId, partDate);
        return new PageResult(total, CommonUtils.parseLong(offset, 0L), concreteMixtureablVoList);
    }


    /**
     * 删除混凝土拌和物性能
     * @param request
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月17日
     */
    @RequestMapping(value = "/scene/delConcreteMixtureablData",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delConcreteMixtureablData(HttpServletRequest request, Long id){

        if(id == null){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }

        int result = detecTionService.delConcreteMixtureablData(id);
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "删除成功");
        }
    }

    /**
     * 导出混凝土拌和物性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/exportConcreteMixtureablData",method = RequestMethod.GET)
    @ResponseBody
    public void exportConcreteMixtureablData(HttpServletRequest request, HttpServletResponse response){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        detecTionService.exportConcreteMixtureablData(beamId, offset, limit, noticeId, partDate, response);
    }

    /**
     * 更新混凝土力学性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/updateMechanics",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateMechanics(HttpServletRequest request){
        String mechanicsJson = request.getParameter("mechanicsJson");
        if(StringUtils.isEmpty(mechanicsJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            ConcreteMechanics concreteMechanics = JSON.parseObject(mechanicsJson, ConcreteMechanics.class);
            if(concreteMechanics.getId() == null){
                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
            }
            result = detecTionService.updateMechanics(concreteMechanics, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }
    /**
     * 获取混凝土力学性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/readConcreteMechanicsData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readConcreteMechanicsData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        List<ConcreteMechanicsVo> concreteMechanicsVoList = detecTionService.getConcreteMechanicsData(beamId, offset, limit, noticeId, partDate);
        long total = detecTionService.countConcreteMechanicsData(beamId, noticeId, partDate);
        return new PageResult(total, CommonUtils.parseLong(offset, 0L), concreteMechanicsVoList);
    }
    /**
     * 删除混凝土力学性能
     * @param request
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月17日
     */
    @RequestMapping(value = "/scene/delConcreteMechanicsData",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delConcreteMechanicsData(HttpServletRequest request, Long id){

        if(id == null){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }

        int result = detecTionService.delConcreteMechanicsData(id);
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "删除成功");
        }
    }

    /**
     * 导出混凝土拌和物性能
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/exportConcreteMechanicsData",method = RequestMethod.GET)
    @ResponseBody
    public void exportConcreteMechanicsData(HttpServletRequest request, HttpServletResponse response){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        detecTionService.exportConcreteMechanicsData(beamId, offset, limit, noticeId, partDate, response);
    }
    /**
     * 更新管道压浆
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/updatePipeGrouting",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updatePipeGrouting(HttpServletRequest request){
        String pipeGroutingJson = request.getParameter("pipeGroutingJson");
        if(StringUtils.isEmpty(pipeGroutingJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            PipeGrouting pipeGrouting = JSON.parseObject(pipeGroutingJson, PipeGrouting.class);
            if(pipeGrouting.getId() == null){
                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
            }
            result = detecTionService.updatePipeGrouting(pipeGrouting, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }
    /**
     * 获取管道压浆
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/readPipeGroutingData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readPipeGroutingData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        List<PipeGroutingVo> pipeGroutingVoList = detecTionService.getPipeGroutingData(beamId, offset, limit, noticeId, partDate);
        long total = detecTionService.countPipeGroutingData(beamId, noticeId, partDate);
        return new PageResult(total, CommonUtils.parseLong(offset, 0L), pipeGroutingVoList);
    }

    /**
     * 删除管道压浆
     * @param request
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月17日
     */
    @RequestMapping(value = "/scene/delPipeGroutingData",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delPipeGroutingData(HttpServletRequest request, Long id){

        if(id == null){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }

        int result = detecTionService.delPipeGroutingData(id);
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "删除成功");
        }
    }

    /**
     * 导出管道压浆
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/exportPipeGroutingData",method = RequestMethod.GET)
    @ResponseBody
    public void exportPipeGroutingData(HttpServletRequest request, HttpServletResponse response){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        detecTionService.exportPipeGroutingData(beamId, offset, limit, noticeId, partDate, response);
    }

    /**
     * 更新地基承载力
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/updateGroundBearer",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateGroundBearer(HttpServletRequest request){
        String groundBearerJson = request.getParameter("groundBearerJson");
        if(StringUtils.isEmpty(groundBearerJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            GroundBearer groundBearer = JSON.parseObject(groundBearerJson, GroundBearer.class);
//            if(groundBearer.getId() == null){
//                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
//            }
            result = detecTionService.updateGroundBearer(groundBearer, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }
    /**
     * 获取地基承载力
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/readGroundBearerData",method = RequestMethod.GET)
    @ResponseBody
    public PageResult readGroundBearerData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        List<GroundBearerVo> groundBearerVoList = detecTionService.getGroundBearerData(beamId, offset, limit, noticeId, partDate);
        long total = detecTionService.countGroundBearerData(beamId, noticeId, partDate);
        return new PageResult(total, CommonUtils.parseLong(offset, 0L), groundBearerVoList);
    }

    /**
     * 删除地基承载力
     *
     * @param request
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月17日
     */
    @RequestMapping(value = "/scene/delGroundBearerData",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delGroundBearerData(HttpServletRequest request, Long id){

        if(id == null){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }

        int result = detecTionService.delGroundBearerData(id);
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "删除成功");
        }
    }

    /**
     * 导出地基承载力
     * @param request
     * @return
     */
    @RequestMapping(value = "/scene/exportGroundBearerData",method = RequestMethod.GET)
    @ResponseBody
    public void exportGroundBearerData(HttpServletRequest request, HttpServletResponse response){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        Long beamId = super.getBeamId(request);
        detecTionService.exportGroundBearerData(beamId, offset, limit, noticeId, partDate, response);
    }

    /**
     * 获取混凝土理论配合比试配单
     * @param concreteEntrustId 委托单id
     * @return
     * modified by ljp  2020-03-29 获取配合比额外参数
     */
    @RequestMapping(value = "/getConcreteMixratio",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getConcreteMixratio(String concreteEntrustId){
        if(StringUtils.isEmpty(concreteEntrustId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        List<ConcreteTheoryMixratio> concreteTheoryMixratios = detecTionService.getConcreteTheoryMixratio(concreteEntrustId);

        ConcreteEntrust concreteEntrust = detecTionService.getAddConcreteMixratio(Long.parseLong(concreteEntrustId));

        HashMap<String,Object> result = new HashMap();
        result.put("ConcreteTheoryMixratio",concreteTheoryMixratios);
        result.put("AddedConcreteMixratio",concreteEntrust);
        return new ApiResult(result);
    }

    /**
     * 获取混凝土理论配合比试配单
     * @param fileId
     * @return
     */
    @RequestMapping(value = "/deleteConcreteFiles",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult deleteConcreteFileInfo(HttpServletRequest request, String fileId, String fileName) {
        if (StringUtils.isEmpty(fileId)) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        FileInfo fileInfo = fileService.getFileById(Long.parseLong(fileId));
        List<File> files=null;
        if (fileInfo != null) {
            String workPath = fileInfo.getFile_path();
            workPath = uploadFilePath + File.separator + workPath;
            files = FileUtil.fileList(workPath);

            String filePath;

            for(int i=0; i<files.size(); i++) {
                filePath = files.get(i).getPath();
                int startIndex = filePath.toLowerCase().indexOf(fileName.toLowerCase());
                if (startIndex>=0) {
                    // 删除 文件
                   files.get(i).delete();

                }
            }
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "删除文件成功！");

        }
        return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());

    }
    /**
     * 获取混凝土理论配合比试配单
     * @param fileId
     * @return
     */
    @RequestMapping(value = "/getConcreteFiles",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getConcreteFileInfo(HttpServletRequest request, String fileId){
        if(StringUtils.isEmpty(fileId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        FileInfo fileInfo = fileService.getFileById(Long.parseLong(fileId));
        List<File> files=null;
        if (fileInfo != null) {
            String workPath = fileInfo.getFile_path();
            workPath = uploadFilePath + File.separator + workPath;
            files = FileUtil.fileList(workPath);

            //转换成下载地址
            String fileUrl;
            String filePath;
            List resultList = new ArrayList(files.size());
            for(int i=0; i<files.size(); i++) {
                filePath = files.get(i).getPath();
                int startIndex = filePath.toLowerCase().indexOf(uploadFilePath.toLowerCase());
                filePath = filePath.substring(startIndex + uploadFilePath.length());
                filePath = filePath.replace(File.separatorChar,'/');
                fileUrl =  fileRootUrl + filePath;
                resultList.add(fileUrl);
            }
            return new ApiResult(resultList);

        }
        return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
    }
    /**
     * 保存混凝土理论配合比试配单
     * @param mixratioListJson
     * @param request
     * @param addedMixratioJson : 配合比额外参数
     * @return
     * modified by ljp 2020-03-29 增加配合比额外参数，根据陶工的要求
     */
    @RequestMapping(value = "/saveConcreteMixratio",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveConcreteMixratio(@RequestParam("mixratioListJson") String mixratioListJson,
                                          @RequestParam("addedMixratioJson") String addedMixratioJson,
                                          @RequestParam("entrustId") String entrustId,
                                          HttpServletRequest request){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        if(StringUtils.isEmpty(mixratioListJson) || StringUtils.isEmpty(entrustId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        int result = 0;
        try {
            JSONObject addedMixratio = JSON.parseObject(addedMixratioJson);
            log.info("addedMixratio:" + addedMixratio.toJSONString());


            List<ConcreteTheoryMixratio> concreteTheoryMixratios = JSON.parseArray(mixratioListJson, ConcreteTheoryMixratio.class);
            result = detecTionService.saveConcreteTheoryMixratio(userId, beamId, concreteTheoryMixratios, entrustId, addedMixratio);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }   /**
     * 保存试验结果
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveLabSampres")
    @ResponseBody
    public ApiResult saveLabSampres(HttpServletRequest request, LabSampres labSampres){
        if (labSampres==null){
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(),HttpResultEnum.EXCEPTION.getMessage());
        }
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
//        //处理接收的文件
//        if (labSampres.getSample_unit()==2) {
//            MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
//            CommonsMultipartFile file = (CommonsMultipartFile) mRequest.getFile("file");
//            Long id = saveFile(file);
//            labSampres.setFile_id(id);
//        }
        ApiResult apiResult=detecTionService.saveLabSampres(labSampres,userId,beamId);
        return apiResult;
    }

    /**
     * 委托单
     * @return
     */
    @RequestMapping(value = "/weituodan",method = RequestMethod.GET)
    public ModelAndView weituodan(){
        return new ModelAndView();
    }

    /**
     * 保存取样单
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveLabSampling",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult saveLabSampling(HttpServletRequest request){
        String sampler = request.getParameter("sampler");
        String witness = request.getParameter("witness");
        String consigner = request.getParameter("consigner");
        String authorize_agency = request.getParameter("authorize_agency");
        String receiver = request.getParameter("receiver");
        String authorize_phone = request.getParameter("authorize_phone");
        String basend_date = request.getParameter("basend_date");
        String inbound_check_id = request.getParameter("inbound_check_id");
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.saveLabSampling(sampler,witness,consigner,authorize_agency,receiver,authorize_phone,basend_date,inbound_check_id,userId,beamId);
        return apiResult;
    }
    /**
     * 保存结果通知
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveLabSampresReply",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult saveLabSampling(HttpServletRequest request, LabSampresReply labSampresReply){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.saveLabSampresReply(labSampresReply,userId,beamId);
        return apiResult;
    }
    /**
     * 更新取样单
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateLabSampling")
    @ResponseBody
    public ApiResult updateLabSampling(HttpServletRequest request, LabSampling labSampling,String sample_date2,String basend_date2,String delivery_date2){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.updateLabSampling(labSampling,sample_date2,basend_date2,delivery_date2,userId,beamId);
        return apiResult;
    }
    /**
     * 获取取样单
     * @param request
     * @return
     */
    @RequestMapping(value = "/getLabSampling")
    @ResponseBody
    public ApiResult getLabSampling(HttpServletRequest request){
        String inbound_check_id = request.getParameter("inbound_check_id");
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.getLabSampling(inbound_check_id,userId,beamId);
        return apiResult;
    }
    /**
     * 获取试验结果回复
     * @param request
     * @return
     */
    @RequestMapping(value = "/getLabSampresReply")
    @ResponseBody
    public ApiResult getLabSampresReply(HttpServletRequest request){
        String inbound_check_id = request.getParameter("inbound_check_id");
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.getLabSampresReply(inbound_check_id,userId,beamId);
        return apiResult;
    }
    /**
     * 获取施工通知单
     * @param request
     * @return
     */
    @RequestMapping(value = "/getConcreteRearatio")
    @ResponseBody
    public ApiResult getConcreteRearatio(HttpServletRequest request){
        String concrete_rearatio_id = request.getParameter("concrete_rearatio_id");
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.getConcreteRearatio(concrete_rearatio_id,userId,beamId);
        return apiResult;
    }
    /**
     * 获取试验结果
     * @param request
     * @return
     */
    @RequestMapping(value = "/getLabSampres")
    @ResponseBody
    public ApiResult getLabSampres(HttpServletRequest request){
        String inbound_check_id = request.getParameter("inbound_check_id");
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult=detecTionService.getLabSampres(inbound_check_id,userId,beamId);
        return apiResult;
    }
    /**
     * 获取开盘证
     * @param request
     * @return
     */
    @RequestMapping(value = "/getKaiPanZheng")
    @ResponseBody
    public ApiResult getKaiPanZheng(HttpServletRequest request){
        String id = request.getParameter("id");
        ApiResult apiResult=detecTionService.getKaiPanZheng(id);
        return apiResult;
    }

    /**
     * 获取强度报告
     * @param request
     * @return
     */
    @RequestMapping(value = "/getConcreteDensity")
    @ResponseBody
    public ApiResult getConcreteDensity(HttpServletRequest request){
        String id = request.getParameter("id");
        ApiResult apiResult=detecTionService.getConcreteDensity(id);
        return apiResult;
    }


    @RequestMapping(value = "/quyangdan",method = RequestMethod.GET)
    public ModelAndView quyangdan(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/editQuyangdan",method = RequestMethod.GET)
    public ModelAndView editQuyangdan(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/jieguotongzhi",method = RequestMethod.GET)
    public ModelAndView jieguotongzhi(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/jieguotongzhiDetail",method = RequestMethod.GET)
    public ModelAndView jieguotongzhiDetail(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres0",method = RequestMethod.GET)
    public ModelAndView other(){
    	return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres1",method = RequestMethod.GET)
    public ModelAndView shuini(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampresDetail1",method = RequestMethod.GET)
    public ModelAndView sampresDetail1(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres2",method = RequestMethod.GET)
    public ModelAndView fenmeihui(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres3",method = RequestMethod.GET)
    public ModelAndView kuangfen(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres4",method = RequestMethod.GET)
    public ModelAndView xiguliao(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres5",method = RequestMethod.GET)
    public ModelAndView cuguliao(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres6",method = RequestMethod.GET)
    public ModelAndView jianshuiji(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres7",method = RequestMethod.GET)
    public ModelAndView yinqiji(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres8",method = RequestMethod.GET)
    public ModelAndView pengzhangji(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres9",method = RequestMethod.GET)
    public ModelAndView gangjiaoxian(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres10",method = RequestMethod.GET)
    public ModelAndView gangjin(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres11",method = RequestMethod.GET)
    public ModelAndView miaoju(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres12",method = RequestMethod.GET)
    public ModelAndView fangshuituliao(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres13",method = RequestMethod.GET)
    public ModelAndView yaliaojiang(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres14",method = RequestMethod.GET)
    public ModelAndView xieshuiguan(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres15",method = RequestMethod.GET)
    public ModelAndView bowenguan(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/result/sampres16",method = RequestMethod.GET)
    public ModelAndView qita(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/concrete_mix_cons",method = RequestMethod.GET)
    public ModelAndView concrete_mix_cons(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/shigongshengqingdan",method = RequestMethod.GET)
    public ModelAndView shigongshengqingdan(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/shigongshengqingdanDetail",method = RequestMethod.GET)
    public ModelAndView shigongshengqingdanDetail(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/kaipanzheng",method = RequestMethod.GET)
    public ModelAndView kaipanzheng(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/kaipanzhengOS",method = RequestMethod.GET)
    public ModelAndView kaipanzhengOS(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/baogao",method = RequestMethod.GET)
    public ModelAndView baogao(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/concrete_concrete_density",method = RequestMethod.GET)
    public ModelAndView concrete_concrete_density(){
        return new ModelAndView();
    }


    /**
     * 获取开盘证列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/getLabConcreteOpeningList")
    @ResponseBody
    public PageResult getLabConcreteOpeningList(HttpServletRequest request, long offset, int limit){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        String noticeId = request.getParameter("notice_id");
        String partDate = request.getParameter("part_date");
        PageResult labConcreteOpeningList = detecTionService.getLabConcreteOpeningList(userId, beamId, offset, limit, noticeId, partDate);
        return labConcreteOpeningList;
    }

    /**
     * 获取混凝土施工配合比
     * @param request
     * @return
     */
    @RequestMapping(value = "/readConsMixratioData", method = RequestMethod.GET)
    @ResponseBody
    public PageResult readConsMixratioData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String concreteRearatioId = request.getParameter("concrete_rearatio_id");
        if(StringUtils.isEmpty(concreteRearatioId)){
            return null;
        }
        return detecTionService.getConsMixratioData(offset, limit, concreteRearatioId);
    }

    /**
     * 获取新的施工配料通知单单号
     * @return
     */
    @RequestMapping(value = "/getNewRearatioNoticeNo",method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getNewRearatioNoticeNo(){
        String no = UUID.randomUUID().toString();
        return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage(), no);
    }
    /**
     *  保存混凝土施工配料通知单
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveConcreteRearatio")
    @ResponseBody
    public ApiResult saveConcreteRearatio(HttpServletRequest request, ConcreteRearatio concreteRearatio,String time){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        String mixratioListJson = request.getParameter("mixratioListJson");
        if(StringUtils.isEmpty(mixratioListJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (StringUtils.isNotBlank(time)){
                Date parse = simpleDateFormat.parse(time);
                concreteRearatio.setRearatio_notice_date(parse);
            }
        } catch (ParseException e) {
            e.printStackTrace();
            return new ApiResult("500","请输入正确的日期");
        }
        Long id = null;
        try{
            List<ConcreteConsMixratio> concreteConsMixratioList = JSON.parseArray(mixratioListJson, ConcreteConsMixratio.class);
            id = detecTionService.saveConcreteRearatio(userId, beamId, concreteRearatio, concreteConsMixratioList);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (id == null) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), HttpResultEnum.SUCCESS.getMessage(), id);
        }
    }
    /**
     *  保存强度检验
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveConcreteDensity")
    @ResponseBody
    public ApiResult saveConcreteDensity(HttpServletRequest request, ConcreteDensity concreteDensity){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        ApiResult apiResult = detecTionService.saveConcreteDensity(userId, beamId, concreteDensity);
        return apiResult;
    }

    /**
     * 新建抗压试验
     * @param request
     * @param
     * @return
     * @author anruoxin
     * 2019年4月12日
     */
    @RequestMapping(value = "/addConcreteDensity")
    @ResponseBody
    public ApiResult addConcreteDensity(HttpServletRequest request,String beam_no, String test_date, String llphbph){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        if(StringUtils.isEmpty(beam_no) || StringUtils.isEmpty(test_date)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        ConcreteDensity concreteDensity = new ConcreteDensity();
        concreteDensity.setBeam_no(beam_no);
        concreteDensity.setLlphbph(llphbph);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date;
		try {
			date = simpleDateFormat.parse(test_date);
			concreteDensity.setTest_date(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        ApiResult apiResult = detecTionService.addConcreteDensity(userId, beamId, concreteDensity);
        return apiResult;
    }

    /**
     * 删除抗压试验
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月12日
     */
    @RequestMapping(value = "/delConcreteDensity")
    @ResponseBody
    public ApiResult delConcreteDensity(Long id){
    	if (id != null) {
    		return detecTionService.delConcreteDensity(id);
        }else  {
        	ApiResult apiResult = new ApiResult();
            apiResult.setMessage("未获取到删除的管理人员");
            apiResult.setCode("500");
            return  apiResult;
        }
    }

    /**
     * 导出抗压试验列表
     */

    @RequestMapping(value = "/exportLabConcreteDensityData")
    @ResponseBody
    public void exportLabConcreteDensityData(HttpServletRequest request, String offset, String limit,String notice_id,String part_date, HttpServletResponse response){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        detecTionService.exportLabConcreteDensityData(userId, beamId, offset, limit, notice_id, part_date, response);

    }
    /**
     * 获取抗压试验列表
     */

    @RequestMapping(value = "/getLabConcreteDensityList")
    @ResponseBody
    public PageResult getLabConcreteDensityList(HttpServletRequest request, String offset, String limit,String notice_id,String part_date){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        PageResult labConcreteOpeningList = detecTionService.getLabConcreteDensityList(userId, beamId, offset, limit, notice_id, part_date);
        return labConcreteOpeningList;
    }
    /**
     * 配合比审核
     */
    @RequestMapping(value = "/saveEntrustCheck")
    @ResponseBody
    public  ApiResult saveEntrustCheck(HttpServletRequest request,long id,int state,String opinion){
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        return detecTionService.saveEntrustCheck(id, state, userId,beamId,opinion);
    }
    /**
     * 获取配合比审核意见
     */
    @RequestMapping(value = "/getEntrustCheck",method = RequestMethod.GET)
    @ResponseBody
    public  ApiResult getEntrustCheck(HttpServletRequest request,Long id,Integer state){
        return detecTionService.getEntrustCheck(id, state);
    }

    @RequestMapping(value = "/concrete_mix_design_check",method = RequestMethod.GET)
    public ModelAndView concrete_mix_design_check(){
        return new ModelAndView();
    }

    /**
     * 添加回弹法混凝土强度列表
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addHuitanfaList")
    @ResponseBody
    public ApiResult addHuitanfaList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return detecTionService.addHuitanfaList(detailJson, beamId, userId);
    }

    /**
     * 更新回弹法混凝土强度
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateHuitanfa",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateHuitanfa(HttpServletRequest request){
        String detailJson = request.getParameter("detailJson");
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long userId = super.getUserId(request);
        int result;
        try{
            LabHtfhntqd labHtfhntqd = JSON.parseObject(detailJson, LabHtfhntqd.class);
            if(labHtfhntqd.getId() == null){
                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
            }
            result = detecTionService.updateHuitanfa(labHtfhntqd,userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 获取回弹法强度
     * @param request
     * @return
     */
    @RequestMapping("/getHuitanfa")
    @ResponseBody
    public ApiResult getHuitanfa( HttpServletRequest request,Long id){
        return detecTionService.getHuitanfa(id);
    }

    /**
     * 添加钢筋保护层强度列表
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addGangjinbaohuList")
    @ResponseBody
    public ApiResult addGangjinbaohuList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return detecTionService.addGangjinbaohuList(detailJson, beamId, userId);
    }

    /**
     * 更新钢筋保护层强度
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateGangjinbaohu",method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updateGangjinbaohu(HttpServletRequest request){
        String detailJson = request.getParameter("detailJson");
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long userId = super.getUserId(request);
        int result;
        try{
            LabGjbhchd labGjbhchd = JSON.parseObject(detailJson, LabGjbhchd.class);
            if(labGjbhchd.getId() == null){
                return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
            }
            result = detecTionService.updateGangjinbaohu(labGjbhchd,userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 获取钢筋保护层强度
     * @param request
     * @return
     */
    @RequestMapping("/getGangjinbaohu")
    @ResponseBody
    public ApiResult getGangjinbaohu( HttpServletRequest request,Long id){
        return detecTionService.getGangjinbaohu(id);
    }

    /**
     * 获取回弹法强度度标段下拉框
     * @param request
     * @return
     */
    @RequestMapping("/getHuitanfaBiaoDuan")
    @ResponseBody
    public ApiResult getHuitanfaBiaoDuan( HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        return detecTionService.getHuitanfaBiaoDuan(beamId);
    }

    /**
     * 获取钢筋保护标段下拉框数据
     * @param request
     * @return
     */
    @RequestMapping("/getGangjinbaohuBiaoDuan")
    @ResponseBody
    public ApiResult getGangjinbaohuBiaoDuan( HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        return detecTionService.getGangjinbaohuBiaoDuan(beamId);
    }

    /**
     * 回弹法强度列表获取
     * @param request
     * @param bid
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/getHuitanfaList")
    @ResponseBody
    public PageResult getHuitanfaList( HttpServletRequest request,String bid,String offset,String limit){
        Long beamId = super.getBeamId(request);
        String startDate = request.getParameter("start_date");
        String endDate = request.getParameter("end_date");
        PageResult huitanfaList = detecTionService.getHuitanfaList(beamId, bid, offset, limit, startDate, endDate);
        return huitanfaList;
    }

    /**
     * 导出回弹法强度列表
     * @param request
     * @param bid
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/exportHuitanfaData")
    @ResponseBody
    public void exportHuitanfaData( HttpServletRequest request,String bid,String offset,String limit, HttpServletResponse response){
        Long beamId = super.getBeamId(request);
        String startDate = request.getParameter("start_date");
        String endDate = request.getParameter("end_date");
        detecTionService.exportHuitanfaData(beamId, bid, offset, limit, startDate, endDate, response);
    }

    /**
     * 钢筋保护强度列表获取
     * @param request
     * @param bid
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/getGangjinbaohuList")
    @ResponseBody
    public PageResult getGangjinbaohuList( HttpServletRequest request,String bid,String offset,String limit){
        Long beamId = super.getBeamId(request);
        String startDate = request.getParameter("start_date");
        String endDate = request.getParameter("end_date");
        PageResult huitanfaList = detecTionService.getGangjinbaohuList(beamId, bid, offset, limit, startDate, endDate);
        return huitanfaList;
    }

    /**
     * 导出钢筋保护强度
     * @param request
     * @param bid
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/exportGangjinbaohuData")
    @ResponseBody
    public void exportGangjinbaohuData( HttpServletRequest request,String bid,String offset,String limit, HttpServletResponse response){
        Long beamId = super.getBeamId(request);
        String startDate = request.getParameter("start_date");
        String endDate = request.getParameter("end_date");
        detecTionService.exportGangjinbaohuData(beamId, bid, offset, limit, startDate, endDate, response);
    }

    /**
     * 导出混凝土施工配料通知单
     * @return
     */

    @RequestMapping(value = "/exportConcreteRearatio")
    @ResponseBody
    public ApiResult exportConcreteRearatio(Long concreteRearatioId, String structuralParts, HttpServletResponse response,HttpServletRequest request){

        return detecTionService.exportConcreteRearatio(concreteRearatioId,structuralParts,response);
    }


    /**
     * 获取土工试验
     * @param request
     * @return
     */
    @RequestMapping(value = "/readGeotechnicalData", method = RequestMethod.GET)
    @ResponseBody
    public PageResult readGeotechnicalData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String name = request.getParameter("name");
        Long beamId = super.getBeamId(request);

        return detecTionService.readGeotechnicalData(offset, limit, beamId, name);
    }


    /**
     * 删除土工试验
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月12日
     */
    @RequestMapping(value = "/delGeotechnicalData")
    @ResponseBody
    public ApiResult delGeotechnicalData(Long id){
        return detecTionService.delGeotechnicalData(id);
    }

    /**
     * 根据ID获取土工试验
     * @param id
     * @return
     * @author anruoxin
     * 2019年4月12日
     */
    @RequestMapping(value = "/getGeotechnicalDataById")
    @ResponseBody
    public ApiResult getGeotechnicalDataById(Long id){
        return detecTionService.getGeotechnicalDataById(id);
    }

    /**
     * 新增土工试验
     * @param request
     * @param geotechnicalJson
     * @return
     */
    @RequestMapping("/doSaveGeotechnical")
    @ResponseBody
    public ApiResult doSaveGeotechnical(HttpServletRequest request, String geotechnicalJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return detecTionService.doSaveGeotechnical(beamId, userId, geotechnicalJson);
    }

    @RequestMapping("/getProcessLabData")
    @ResponseBody
    public ApiResult getProcessLabData(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        return detecTionService.getProcessLabData(noticeId);
    }

    private String getTempPath() {
        String savePath = CommonUtils.getTimeFormat(new Date(), "yyyyMMdd") + File.separator;
        String path = uploadTempPath + savePath;
        return path;
    }

    /*
     * 上传多个文件,后台代码主要是接收参数，其他的业务代码根据你们具体的业务需求来定
     */
    @RequestMapping(value = "/uploadBatch", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ApiResult uploadBatch(@RequestParam("file") MultipartFile[] files, String entrustId,String fileInfoId, String tempDir) {
        String workPath="";
        String briefWorkPath = "";
        boolean isNewFileInfo = false;
        ApiResult result = new ApiResult();
        //log.info("fileDirServerSide=" +fileDirServerSide);
        final List<FileInfoVo> files_re = new ArrayList<FileInfoVo>();

        //20200315： 创建附件信息，把附件的file_id保存到t_concrete_entrust表（混凝土试验委托单）中
        try {
            if (files.length>0) {


                // 移动文件到指定路径
                FileInfo fileInfo = null;
                if (fileInfoId.trim().length()>0) {
                    // 获取文件保存路径
                    fileInfo = fileService.getFileById(Long.parseLong(fileInfoId));
                    if (fileInfo != null) {
                        tempDir = fileInfo.getFile_path();
                        if (tempDir.endsWith(File.separator)) {
                            workPath = uploadFilePath + tempDir;
                        }else {
                            workPath = uploadFilePath + File.separator + tempDir;
                        }

                        CommonUtils.checkPath(workPath);
                    }
                }

                if (fileInfo == null) {
                    // 从数据库里面再查一次, 原因是上传多个文件， 请求会调用多次
                    fileInfo = detecTionService.getConcreteEntrustFileInfo(Long.parseLong(entrustId));
                    if (fileInfo != null) {
                        tempDir = fileInfo.getFile_path();
                        if (tempDir.endsWith(File.separator)) {
                            workPath = uploadFilePath + tempDir;
                        }else {
                            workPath = uploadFilePath + File.separator + tempDir;
                        }

                        CommonUtils.checkPath(workPath);
                    }
                }
                if (fileInfo == null) {
                    fileInfo = new FileInfo();
                    workPath = getWorkPath();
                    workPath = workPath  + tempDir;
                    CommonUtils.checkPath(workPath);
                    isNewFileInfo = true;
                }
                briefWorkPath = workPath.substring(workPath.indexOf(uploadFilePath) + uploadFilePath.length());
                fileInfo.setAdd_time(new Date());
                fileInfo.setFile_path(briefWorkPath);
                log.info("briefWorkPath=" + briefWorkPath);
                fileInfo.setFormer_name("");
                fileInfo.setOriginal_name("");
                if (isNewFileInfo) {
                    fileInfo = fileService.saveFileInfo(fileInfo);
                }else
                {
                    fileInfo = fileService.updateFileInfo(fileInfo);
                }
                detecTionService.saveConcreteEntrustFileInfo(Long.parseLong(entrustId),fileInfo.getFileid());
            }
            for(int i=0;i<files.length;i++){
                if (!files[i].isEmpty()) {
                    String originalname = files[i].getOriginalFilename();
                    if(StringUtils.isEmpty(originalname)) { continue; }

                    //String contentType = files[i].getContentType();
                    //String suffixname = originalname.substring(originalname.lastIndexOf("."));
                    //FileInfoVo uploadFile = new FileInfoVo();
                    //uploadFile.setFile_name(originalname);
                    //uploadFile.setFile_type(contentType);
                    String filename = workPath + File.separator + originalname;

                    File tfile = new File(filename);

                    files[i].transferTo(tfile); // 存储服务器临时文件，设置定时任务清理30天前的

                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            result.setCode("2");
            result.setMessage("服务器端异常:" + e.getMessage());
        }
        result.setCode("5");
        result.setMessage("上传成功！");
        result.setResult(workPath);
        return result;
    }


    private String getWorkPath() {
        String savePath = CommonUtils.getTimeFormat(new Date(), "yyyyMMdd") + File.separator;
        String path = uploadFilePath + savePath;
        return path;
    }
}
